//
//  UIButton+Extension.swift
//  Weobo
//
//  Created by 史亚洲 on 16/1/17.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIButton {
//指定图片和背景图片(加号按钮)
    convenience init(imageName: String?,backImageName: String?) {
        
       self.init()
        if imageName != nil {
        //1.2设置按钮图片
       setImage(UIImage(named: imageName!), forState: .Normal)
       setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)
        }
        //1.3设置按钮背景图片
        if backImageName != nil{
       setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
       setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Highlighted)
        }
        sizeToFit()

    
    }
    
    //修改登录和注册按钮
    convenience init(title: String,color: UIColor,fontSize: CGFloat,backImageName: String?,imageName: String? = nil) {
        self.init()
         setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        if backImageName != nil {
        setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        }
        if imageName != nil {
        setImage(UIImage(named: imageName!), forState: .Normal)
        
        }
        sizeToFit()
        
    
    }


}
